import os

from PIL import Image

classes = ["Abyssinian", "Bengal", "Birman", "Bombay", "British_Shorthair", "Egyptian_Mau", "Maine_Coon", "Persian", "Ragdoll", "Russian_Blue", "Siamese", "Sphynx"]

crsPath = 'D:/work/test/'

news_folder = "D:/work/dataset/ts"

for i in classes:
    original_folder = crsPath + i +"/"
    prefix = i
    num = 300
    for filename in os.listdir(original_folder):
        # 确定文件是图片文件
        num += 1
        if filename.endswith('.jpg'):
            # 构造原始文件的完整路径
            original_filepath = os.path.join(original_folder, filename)

            # 打开图片并处理
            with Image.open(original_filepath) as img:
                # 进行图片处理操作，例如调整大小、裁剪、滤镜等

                # 构造目标文件名
                new_filename = prefix + "_" + str(num)+filename[-4:]

                # 构造目标文件的完整路径
                new_filepath = os.path.join(news_folder, new_filename)
                if img.mode == "P":
                    img = img.convert('RGB')

                # 保存修改后的图片
                img.save(new_filepath)